<%@ Language=VBScript %>
<%	
	set Conn=server.CreateObject("ADODB.Connection")
	Conn.Open application("StrConn")
	nodeid=Request("id")
	'userid=request("user")
	userid=request("canbo")
	IDFlow=request("IDFlow")
	Yeucau=Request("Yeucau")
	'*********Gui theo ca nhan*********	
		bTemp=nodeid
		if CheckNumberNode(bTemp,99,1) then 'Kiem tra so luong nhanh trong mot node=99
			sql1="Insert Into TvFlowNode(Maworkflownode,Maworkflow,nguoixuly,yeucauxuly) values('" & nodeid & "','" & IDFlow & "','" & userid & "','"& Yeucau &"')"
			conn.Execute sql1
		end if
	conn.Close	
	set conn=nothing
	lnk="../frmTvflowNodecd.asp?IDFlow="& IDFlow
	Response.Redirect(lnk)	
%>
<!--#include file="..\..\jvfunction.inc"-->
<script language=VBScript runat=server>
	'Vi tri bit so sanh
Function ItemLast(Item)
        Dim i
        Dim It
        Dim Vt
        Dim j
        It = Item
        It = Right(It, Len(It) - 4)
        j = 1
        For i = 2 To Len(It)
            If i < Len(It) Then
                Temp = Mid(It, i, 1)
                i = i + 1
                Temp = Temp & Mid(It, i, 1)
                j = j + 1
                If Temp = "00" Then
                    ItemLast = j - 1
                    Exit For
                Else
                    If i = Len(It) Then
                        ItemLast = j
                    End If
                End If
            End If
        Next
    End Function
    Function CheckNumberNode(nodeid,Max,num)
		dim Vt,bcat
		CheckNumberNode=true
		Vt=ITemLast(nodeid)		
		'5 la maworkflow,3 so chu so toi da cua mot node
		bcat=left(nodeid,5+(Vt-2)*2)& "%%%"		
		for i=Vt to 9
			bcat=bcat & "00"
		Next
		sSQL="Select max(maworkflownode) as bmax from flownode where maworkflownode like '%"& bCat &"%'"
		Set RecPM =server.CreateObject("ADODB.Recordset")
		RecPM.CursorType=3
		RecPM.CacheSize=5
		RecPM.Open sSQL,Conn		
		if not isnull(RecPM("bMax")) then
			bMax=RecPM("bMax")
			bMax=cint(right(left(bMax,5+(ItemLast(bMax)-1)*2),2))
			RecPM.Close
			Set RecPM=nothing
			if (bMax+num)>Max then
				CheckNumberNode=false
			end if		
		end if
End Function
</script>